1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Activities
{
using System;
using System.Runtime;
using System.Collections.ObjectModel;
using System.Activities.Validation;
public struct CodeActivityMetadata
{
Activity activity;
LocationReferenceEnvironment environment;
bool createEmptyBindings;
internal CodeActivityMetadata(Activity activity, LocationReferenceEnvironment environment, bool createEmptyBindings)
{
this.activity = activity;
this.environment = environment;
this.createEmptyBindings = createEmptyBindings;
}
internal bool CreateEmptyBindings
{
get
{
return this.createEmptyBindings;
}
}
public LocationReferenceEnvironment Environment
{
get
{
return this.environment;
}
}
internal Activity CurrentActivity
{
get
{
return this.activity;
}
}
public bool HasViolations
{
get
{
if (this.activity == null)
{
return false;
}
else
{
return this.activity.HasTempViolations;
}
}
}
public static bool operator ==(CodeActivityMetadata left, CodeActivityMetadata right)
{
return left.Equals(right);
}
public static bool operator !=(CodeActivityMetadata left, CodeActivityMetadata right)
{
return !left.Equals(right);
}
public override bool Equals(object obj)
{
if (!(obj is CodeActivityMetadata))
{
return false;
}
CodeActivityMetadata other = (CodeActivityMetadata)obj;
return other.activity == this.activity && other.Environment == this.Environment
&& other.CreateEmptyBindings == this.CreateEmptyBindings;
}
public override int GetHashCode()
{
if (this.activity == null)
{
return 0;
}
else
{
return this.activity.GetHashCode();
}
}
public void Bind(Argument binding, RuntimeArgument argument)
{
ThrowIfDisposed();
Argument.TryBind(binding, argument, this.activity);
}
public void SetValidationErrorsCollection(Collection<ValidationError> validationErrors)
{
ThrowIfDisposed();
ActivityUtilities.RemoveNulls(validationErrors);
this.activity.SetTempValidationErrorCollection(validationErrors);
}
public void AddValidationError(string validationErrorMessage)
{
AddValidationError(new ValidationError(validationErrorMessage));
}
public void AddValidationError(ValidationError validationError)
{
ThrowIfDisposed();
if (validationError != null)
{
this.activity.AddTempValidationError(validationError);
}
}
public void SetArgumentsCollection(Collection<RuntimeArgument> arguments)
{
ThrowIfDisposed();
ActivityUtilities.RemoveNulls(arguments);
this.activity.SetArgumentsCollection(arguments, this.createEmptyBindings);
}
public void AddArgument(RuntimeArgument argument)
{
ThrowIfDisposed();
if (argument != null)
{
this.activity.AddArgument(argument, this.createEmptyBindings);
}
}
public Collection<RuntimeArgument> GetArgumentsWithReflection()
{
return Activity.ReflectedInformation.GetArguments(this.activity);
}
public void AddDefaultExtensionProvider<T>(Func<T> extensionProvider)
where T : class
{
if (extensionProvider == null)
{
throw FxTrace.Exception.ArgumentNull("extensionProvider");
}
this.activity.AddDefaultExtensionProvider(extensionProvider);
}
public void RequireExtension<T>()
where T : class
{
this.activity.RequireExtension(typeof(T));
}
public void RequireExtension(Type extensionType)
{
if (extensionType == null)
{
throw FxTrace.Exception.ArgumentNull("extensionType");
}
if (extensionType.IsValueType)
{
throw FxTrace.Exception.Argument("extensionType", SR.RequireExtensionOnlyAcceptsReferenceTypes(extensionType.FullName));
}
this.activity.RequireExtension(extensionType);
}
internal void ThrowIfDisposed()
{
if (this.activity == null)
{
throw FxTrace.Exception.AsError(new ObjectDisposedException(ToString()));
}
}
internal void Dispose()
{
this.activity = null;
}
}
}
|