public void Add(List<Namespace> namespaces, DocumentedMethod association) { if (association.Method == null) { return; } Namespace ns = this.FindNamespace(association, namespaces); DeclaredType type = this.FindType(ns, association); DeclaredType methodReturnType = DeclaredType.Unresolved( Identifier.FromType(association.Method.ReturnType), association.Method.ReturnType, Namespace.Unresolved(Identifier.FromNamespace(association.Method.ReturnType.Namespace))); Method doc = Method.Unresolved( Identifier.FromMethod(association.Method, association.TargetType), type, association.Method, methodReturnType); this.ParseSummary(association, doc); this.ParseRemarks(association, doc); this.ParseValue(association, doc); this.ParseReturns(association, doc); this.ParseExample(association, doc); foreach (ParameterInfo parameter in association.Method.GetParameters()) { DeclaredType reference = DeclaredType.Unresolved( Identifier.FromType(parameter.ParameterType), parameter.ParameterType, Namespace.Unresolved(Identifier.FromNamespace(parameter.ParameterType.Namespace))); var docParam = new MethodParameter(parameter.Name, reference); this.ParseParamSummary(association, docParam); doc.AddParameter(docParam); } if (this.matchedAssociations.ContainsKey(association.Name)) { return; // weird case when a type has the same method declared twice } this.matchedAssociations.Add(association.Name, doc); if (type == null) { return; } type.AddMethod(doc); }
public void Add( List<Namespace> namespaces, DocumentedMethod association ) { Namespace ns = null; DeclaredType type = null; try { if( association.Method == null ) return; ns = FindNamespace( association, namespaces ); type = FindType( ns, association ); var methodReturnType = DeclaredType.Unresolved( Identifier.FromType( association.Method.ReturnType ), association.Method.ReturnType, Namespace.Unresolved( Identifier.FromNamespace( association.Method.ReturnType.Namespace ) ) ); var doc = Method.Unresolved( Identifier.FromMethod( association.Method, association.TargetType ), type, association.Method, methodReturnType ); ParseSummary( association, doc ); ParseRemarks( association, doc ); ParseValue( association, doc ); ParseReturns( association, doc ); ParseExample( association, doc ); foreach( var parameter in association.Method.GetParameters() ) { var reference = DeclaredType.Unresolved( Identifier.FromType( parameter.ParameterType ), parameter.ParameterType, Namespace.Unresolved( Identifier.FromNamespace( parameter.ParameterType.Namespace ) ) ); var docParam = new MethodParameter( parameter.Name, reference ); ParseParamSummary( association, docParam ); doc.AddParameter( docParam ); } if( matchedAssociations.ContainsKey( association.Name ) ) return; // weird case when a type has the same method declared twice matchedAssociations.Add( association.Name, doc ); if( type == null ) return; type.AddMethod( doc ); } catch( IOException ex ) { var doc = Method.Unresolved( Identifier.FromMethod( association.Method, association.TargetType ), type, association.Method, new NullReference() ); type.AddMethod( doc ); } }
private void WriteObject(object cmdletOutput, MethodParameter methodParameter) { Dbg.Assert(methodParameter != null, "Caller should verify that methodParameter != null"); if ((cmdletOutput != null) && (!string.IsNullOrEmpty(methodParameter.ParameterTypeName))) { PSObject pso = PSObject.AsPSObject(cmdletOutput); if (!pso.TypeNames.Contains(methodParameter.ParameterTypeName, StringComparer.OrdinalIgnoreCase)) { pso.TypeNames.Insert(0, methodParameter.ParameterTypeName); } } this.WriteObject(cmdletOutput); }
public void For_ArrayList() { var parameterInfo = typeof(Tekla.Structures.Model.Assembly) .GetMethods() .FirstOrDefault(m => m.Name.Equals("Add", StringComparison.InvariantCulture) && m.GetParameters().FirstOrDefault().ParameterType.IsAssignableFrom(typeof(System.Collections.ArrayList))) .GetParameters().FirstOrDefault(); var methodParameter = new MethodParameter(parameterInfo); Assert.AreEqual("System.Collections.ArrayList Assemblables_", methodParameter.MethodDeclaration); Assert.AreEqual("var Assemblables = ArrayListConverter.ToTSObjects(Assemblables_);", methodParameter.ConverterToTS); Assert.AreEqual("Assemblables", methodParameter.ParameterName); Assert.AreEqual("Assemblables_ = ArrayListConverter.FromTSObjects(Assemblables);", methodParameter.ConverterFromTS); }
public void For_ArrayofType() { var parameterInfo = typeof(Tekla.Structures.Model.ModelObjectSelector) .GetMethods() .FirstOrDefault(m => m.Name.Equals("GetAllObjectsWithType", StringComparison.InvariantCulture) && m.GetParameters().FirstOrDefault().ParameterType.IsArray) .GetParameters().FirstOrDefault(); var methodParameter = new MethodParameter(parameterInfo); Assert.AreEqual("System.Type[] TypeFilter_", methodParameter.MethodDeclaration); Assert.AreEqual("var TypeFilter = TypeConverter.ToTSObjects(TypeFilter_);", methodParameter.ConverterToTS); Assert.AreEqual("TypeFilter", methodParameter.ParameterName); Assert.AreEqual("TypeFilter_ = TypeConverter.FromTSObject(TypeFilter);", methodParameter.ConverterFromTS); }
public void For_Params_Int() { var parameterInfo = typeof(Tekla.Structures.MacroBuilder) .GetMethods() .FirstOrDefault(m => m.Name.Equals("TableSelect", StringComparison.InvariantCulture) && m.GetParameters().Length > 1) .GetParameters().FirstOrDefault(p => p.GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0); var methodParameter = new MethodParameter(parameterInfo); Assert.AreEqual("params System.Int32[] items", methodParameter.MethodDeclaration); Assert.AreEqual(string.Empty, methodParameter.ConverterToTS); Assert.AreEqual("items", methodParameter.ParameterName); Assert.AreEqual(string.Empty, methodParameter.ConverterFromTS); }
private MethodSignature ReadMethodSignature(MethodBase method) { var parameters = method.GetParameters().Select(ReadParameter).ToList(); MethodParameter returnParameter = null; if (method is MethodInfo nonConstructor && nonConstructor.ReturnType != typeof(void)) { returnParameter = ReadParameter(nonConstructor.ReturnParameter); } return(new MethodSignature { Parameters = parameters, ReturnValue = returnParameter }); }
public void For_Out_Phase() { var parameterInfo = typeof(Tekla.Structures.Model.Beam) .GetMethods() .FirstOrDefault(m => m.Name.Equals("GetPhase", StringComparison.InvariantCulture) && m.GetParameters().Length > 0) .GetParameters().FirstOrDefault(); var methodParameter = new MethodParameter(parameterInfo); Assert.AreEqual("out Dynamic.Tekla.Structures.Model.Phase phase_", methodParameter.MethodDeclaration); Assert.AreEqual("var phase = Dynamic.Tekla.Structures.Model.Phase_.GetTSObject(null);", methodParameter.ConverterToTS); Assert.AreEqual("phase", methodParameter.ParameterName); Assert.AreEqual("phase_ = Dynamic.Tekla.Structures.Model.Phase_.FromTSObject(phase);", methodParameter.ConverterFromTS); }
public void For_List() { var parameterInfo = typeof(Tekla.Structures.Drawing.DatabaseObject) .GetMethods() .FirstOrDefault(m => m.Name.Equals("GetIntegerUserProperties", StringComparison.InvariantCulture) && m.GetParameters().Length > 1) .GetParameters().FirstOrDefault(); var methodParameter = new MethodParameter(parameterInfo); Assert.AreEqual("System.Collections.Generic.List<System.String> names", methodParameter.MethodDeclaration); Assert.AreEqual(string.Empty, methodParameter.ConverterToTS); Assert.AreEqual("names", methodParameter.ParameterName); Assert.AreEqual(string.Empty, methodParameter.ConverterFromTS); }
/// <summary> /// 检测异步回调方法 /// </summary> protected override void checkAsynchronousReturn() { if (methodParameters == null) { base.checkAsynchronousReturn(); if (methodParameters.Length != 0) { if (!methodParameters[0].IsRefOrOut && methodParameters[0].ParameterType.Type == typeof(serverSocketSenderType)) { clientParameterName = methodParameters[0].ParameterName; methodParameters = MethodParameter.Get(methodParameters.getSub(1, methodParameters.Length - 1)); } } } }
public void RefResolveMethodOneParamter_string_Int() { MethodInfo methodInfo = typeof(SampleCls).ResolveMethod("GetCount", new Type[] { typeof(string) }, new MethodParameter[] { MethodParameter.CreateGeneric <string>(true), MethodParameter.Create <int>() }); Assert.IsNotNull(methodInfo); Assert.AreEqual("GetCount", methodInfo.Name); Assert.AreEqual(2, methodInfo.GetParameters().Length); Assert.AreEqual(true, methodInfo.GetParameters()[0].ParameterType.IsByRef); Assert.AreEqual(typeof(string), methodInfo.GetParameters()[0].ParameterType.GetElementType()); Assert.AreEqual(typeof(int), methodInfo.GetParameters()[1].ParameterType); }
/// <summary> /// Determine whether the given dependency carries a value attribute. /// </summary> public Object GetSuggestedValue(DependencyDescriptor descriptor) { Object value = FindValue(descriptor.Attributes); if (value == null) { MethodParameter methodParam = descriptor.MethodParameter; if (methodParam != null) { value = FindValue(methodParam.MethodAttributes); } } return(value); }
public void For_Ref_String() { var parameterInfo = typeof(Tekla.Structures.Model.ModelObject) .GetMethods() .FirstOrDefault(m => m.Name.Equals("GetReportProperty", StringComparison.InvariantCulture) && m.GetParameters().Length > 1) .GetParameters().FirstOrDefault(p => p.ParameterType.IsByRef); var methodParameter = new MethodParameter(parameterInfo); Assert.AreEqual("ref System.String value", methodParameter.MethodDeclaration); Assert.AreEqual(string.Empty, methodParameter.ConverterToTS); Assert.AreEqual("value", methodParameter.ParameterName); Assert.AreEqual(string.Empty, methodParameter.ConverterFromTS); }
private string GetMethodParameterPresentableTypeName(MethodParameter parameter) { var methodLevelGenerics = Regex.Matches(parameter.TypeId, "``+(?<genericParams>\\d)"); var typeText = parameter.TypeId.Replace("{", "<").Replace("}", ">"); var c = 1; if (methodLevelGenerics.Count > 0) { foreach (Match methodLevelGeneric in methodLevelGenerics) { var idx = int.Parse(methodLevelGeneric.Groups["genericParams"].Value); if (idx < parameter.Method.TypeParameters.Count) { typeText = typeText.Replace(methodLevelGeneric.Value, parameter.Method.TypeParameters[idx].Name); } else { typeText = typeText.Replace(methodLevelGeneric.Value, "T" + c); } c++; } } var classLevelGenerics = Regex.Matches(parameter.TypeId, "`+(?<genericParams>\\d)"); if (classLevelGenerics.Count > 0) { foreach (Match classLevelGeneric in classLevelGenerics) { var idx = int.Parse(classLevelGeneric.Groups["genericParams"].Value); if (idx < parameter.Method.ContainingType.TypeParameters.Count) { typeText = typeText.Replace(classLevelGeneric.Value, parameter.Method.ContainingType.TypeParameters[idx].Name); } else { typeText = typeText.Replace(classLevelGeneric.Value, "T" + c); } c++; } } if (typeText.StartsWith(parameter.Method.Model.AssemblyName)) { typeText = typeText.Split(new[] { "." }, StringSplitOptions.None).Last(); } return(typeText); }
public static MethodParameter CreateParameter(string name, SoType soType, bool isRequired) { MethodParameter methodParam = new MethodParameter { Name = name, IsRequired = isRequired, MetaData = new MetaData { DisplayName = name }, SoType = soType, Type = MapHelper.GetTypeBySoType(soType) }; return(methodParam); }
public void For_Type() { var parameterInfo = typeof(Tekla.Structures.Drawing.ViewBase) .GetMethods() .FirstOrDefault(m => m.Name.Equals("GetAllObjects", StringComparison.InvariantCulture) && m.GetParameters().Length > 0 && m.GetParameters().FirstOrDefault().ParameterType.IsAssignableFrom(typeof(System.Type))) .GetParameters().FirstOrDefault(); var methodParameter = new MethodParameter(parameterInfo); Assert.AreEqual("System.Type Type_", methodParameter.MethodDeclaration); Assert.AreEqual("var Type = TypeConverter.ToTSObjects(Type_);", methodParameter.ConverterToTS); Assert.AreEqual("Type", methodParameter.ParameterName); Assert.AreEqual("Type_ = TypeConverter.FromTSObject(Type);", methodParameter.ConverterFromTS); }
private void OnNext(CimMethodResult methodResult) { Dictionary <string, MethodParameter> strs = new Dictionary <string, MethodParameter>(StringComparer.OrdinalIgnoreCase); foreach (MethodParameter methodOutputParameter in base.GetMethodOutputParameters()) { this.ProcessOutParameter(methodResult, methodOutputParameter, strs); } if (strs.Count != 1) { if (strs.Count > 1) { PSObject pSObject = new PSObject(); foreach (KeyValuePair <string, MethodParameter> str in strs) { PSNoteProperty pSNoteProperty = new PSNoteProperty(str.Key, str.Value.Value); pSObject.Properties.Add(pSNoteProperty); } this.WriteObject(pSObject); } } else { MethodParameter methodParameter = strs.Values.Single <MethodParameter>(); if (methodParameter.Value != null) { IEnumerable enumerable = LanguagePrimitives.GetEnumerable(methodParameter.Value); if (enumerable == null) { this.WriteObject(methodParameter.Value, methodParameter); return; } else { foreach (object obj in enumerable) { this.WriteObject(obj, methodParameter); } } } else { return; } } }
/* * // NOTE: This isn't applicable to C# - can't change accessibility * def ensureAccessible[T <: AccessibleObject](accessible: T): T = { * if (!accessible.isAccessible) { * accessible.setAccessible(true) * } * accessible * } */ internal static ParameterHandler <TContext>[] GetParameterHandlers <TContext>(MethodBase method) where TContext : IContext { var methodParameters = method.GetParameters().ToArray(); var handlers = new ParameterHandler <TContext> [methodParameters.Length]; for (var i = 0; i < methodParameters.Length; i++) { var parameter = new MethodParameter(method, i); var contextClass = typeof(TContext); if (IsWithinBounds(parameter.ParameterType, typeof(IContext), contextClass)) { handlers[i] = new ContextParameterHandler <TContext>(); } else if (typeof(IContext).IsAssignableFrom(parameter.ParameterType)) { throw new CloudStateException( $"Unsupported context parameter on [{method.Name}], " + $"[{parameter.ParameterType.Name}] must be the same or a super type of [{contextClass.Name}]" ); } else if (parameter.ParameterType == typeof(IServiceCallFactory)) { handlers[i] = new ServiceCallFactoryParameterHandler <TContext>(); } else if (parameter.Attributes.Any(x => typeof(EntityIdAttribute) == x.GetType())) { if (parameter.ParameterType != typeof(string)) { throw new CloudStateException( $"[EntityIdAttribute] annotated parameter on method {method.Name} " + $"has type {parameter.ParameterType}, but must be String." ); } handlers[i] = new EntityIdParameterHandler <TContext>(); } else { // TODO: revisit extra arguments implementation handlers[i] = new MainArgumentParameterHandler <TContext>(parameter.ParameterType); } } return(handlers); }
private MethodParameter[] PrepareParameters(MethodInfo mInfo, object[] data) // dynamic data { List <MethodParameter> result = new List <MethodParameter>(); int index = 0; foreach (var p in mInfo.GetParameters()) { var t = data[index]; index++; MethodParameter param = new MethodParameter(p.Name, p.ParameterType, t); result.Add(param); } return(result.ToArray()); }
public static MethodParameter CreateParameter(string name, SoType soType, bool isRequired, string description) { MethodParameter methodParam = new MethodParameter { Name = name, IsRequired = isRequired, MetaData = new MetaData { Description = description, DisplayName = AddSpaceBeforeCaptialLetter(name) }, SoType = soType, Type = Convert.ToString(soType) }; return(methodParam); }
public static void WriteElement(MethodGenerator g, string dtoMemberName, Type elementType, Action loadValue) { var method = typeof(IDTOWriter).ResolveMethod("WriteElement", new Type[] { elementType }, MethodParameter.Create <string>(), MethodParameter.Create <bool>(), MethodParameter.CreateGeneric(elementType)); var prmIndex = SerializationArgs.WriterIndex; g.Call(method, () => { g.LoadParameter(prmIndex); g.Load(dtoMemberName); g.Load(IsPrimitive(elementType)); loadValue(); }); }
private static string FormatMethodParameter(MethodParameter parameter) { var builder = new StringBuilder(); for (var i = 0; i < parameter.Modifiers.Count; i++) { builder.Append(parameter.Modifiers[i]); builder.Append(' '); } builder.Append(parameter.TypeName); builder.Append(' '); builder.Append(parameter.ParameterName); return(builder.ToString()); }
public ServiceObjectMethodBuilder AddParameter(string name, SoType soType, bool isRequired = false) { var methodParam = new MethodParameter { Name = name, IsRequired = isRequired, MetaData = new MetaData { DisplayName = name }, SoType = soType, Type = MapHelper.GetTypeBySoType(soType) }; method.MethodParameters.Create(methodParam); return(this); }
private void ProcessOutParameter(CimMethodResult methodResult, MethodParameter methodParameter, IDictionary <string, MethodParameter> cmdletOutput) { Dbg.Assert(methodResult != null, "Caller should verify methodResult != null"); Dbg.Assert(methodParameter != null, "Caller should verify methodParameter != null"); Dbg.Assert(0 != (methodParameter.Bindings & (MethodParameterBindings.Out | MethodParameterBindings.Error)), "Caller should verify that this is an out parameter"); Dbg.Assert(cmdletOutput != null, "Caller should verify cmdletOutput != null"); Dbg.Assert(this.MethodSubject != null, "MethodSubject property should be initialized before starting main job processing"); CimMethodParameter outParameter = methodResult.OutParameters[methodParameter.Name]; object valueReturnedFromMethod = (outParameter == null) ? null : outParameter.Value; object dotNetValue = CimValueConverter.ConvertFromCimToDotNet(valueReturnedFromMethod, methodParameter.ParameterType); if (MethodParameterBindings.Out == (methodParameter.Bindings & MethodParameterBindings.Out)) { methodParameter.Value = dotNetValue; cmdletOutput.Add(methodParameter.Name, methodParameter); var cimInstances = dotNetValue as CimInstance[]; if (cimInstances != null) { foreach (var instance in cimInstances) { CimCmdletAdapter.AssociateSessionOfOriginWithInstance(instance, this.JobContext.Session); } } var cimInstance = dotNetValue as CimInstance; if (cimInstance != null) { CimCmdletAdapter.AssociateSessionOfOriginWithInstance(cimInstance, this.JobContext.Session); } } else if (MethodParameterBindings.Error == (methodParameter.Bindings & MethodParameterBindings.Error)) { var gotError = (bool)LanguagePrimitives.ConvertTo(dotNetValue, typeof(bool), CultureInfo.InvariantCulture); if (gotError) { var errorCodeAsString = (string)LanguagePrimitives.ConvertTo(dotNetValue, typeof(string), CultureInfo.InvariantCulture); CimJobException cje = CimJobException.CreateFromMethodErrorCode(this.GetDescription(), this.JobContext, this.MethodName, errorCodeAsString); throw cje; } } }
public MethodParameter ReadMethodParameter() { var ibyte = (byte)_stream.ReadByte(); if ((ibyte) != 0x0A) { throw new InvalidDataException($"Trying to ReadMethodParameter but streams identifier byte is {ibyte}"); } var name = ReadString(); var val = ReadVariable(); var ret = new MethodParameter { Name = name, Value = val }; return(ret); }
public void AddMemberMethod(object _customerClass, MethodParameter parameter) { CodeMemberMethod method = new CodeMemberMethod(); method.Attributes = MemberAttributes.Public | MemberAttributes.Final; method.Name = parameter.methodName; method.ReturnType = new CodeTypeReference(parameter.methodReturnType); foreach (var item in parameter.methodParameter) { method.Parameters.Add(new CodeParameterDeclarationExpression(item.Key, item.Value)); } method.Statements.Add(new CodeSnippetStatement(parameter.methodSpinnet)); method.Statements.Add(new CodeMethodReturnStatement(new CodeArgumentReferenceExpression(parameter.methodReturn))); CodeTypeDeclaration customerClass = (CodeTypeDeclaration)_customerClass; customerClass.Members.Add(method); }
public void MethodParameter_Ctor_Fills_TypeParserResolver_Property_When_No_Default_Passed() { var param = new MethodParameter(_ExampleMethod_byteArrayWithExpect, null); Assert.AreEqual("byteArrayWithExpect", param.Name); Assert.AreEqual(PathPart.Normalise(param.Name), param.NormalisedName); Assert.AreEqual(typeof(byte[]), param.ParameterType); Assert.AreEqual(false, param.IsOptional); Assert.AreEqual(System.DBNull.Value, param.DefaultValue); Assert.AreEqual(typeof(byte), param.ElementType); Assert.IsTrue(param.IsArray); Assert.IsNotNull(param.TypeParserResolver); var parsers = param.TypeParserResolver.GetParsers(); Assert.AreEqual(1, parsers.Length); Assert.IsInstanceOfType(parsers[0], typeof(ByteArray_Mime64_Parser)); }
/// <summary> /// 检测异步回调方法 /// </summary> protected virtual void checkAsynchronousReturn() { if (methodParameters == null) { methodParameters = Method.Parameters; methodReturnType = Method.ReturnType; if (Method.ReturnType.Type == typeof(void) && methodParameters.Length != 0) { Type type = methodParameters[methodParameters.Length - 1].ParameterType.Type; if (type.IsGenericType) { Type parameterType = null; if (isAsynchronousFunc && type.GetGenericTypeDefinition() == typeof(Func <,>)) { Type[] types = type.GetGenericArguments(); if (types[1] == typeof(bool)) { parameterType = types[0]; } } else if (type.GetGenericTypeDefinition() == typeof(Action <>)) { parameterType = type.GetGenericArguments()[0]; } if (parameterType != null) { if (parameterType == typeof(AutoCSer.Net.TcpServer.ReturnValue)) { isAsynchronousCallback = true; } else if (parameterType.IsGenericType && parameterType.GetGenericTypeDefinition() == typeof(AutoCSer.Net.TcpServer.ReturnValue <>)) { methodReturnType = parameterType.GetGenericArguments()[0]; isAsynchronousCallback = true; } if (isAsynchronousCallback) { methodParameters = MethodParameter.Get(methodParameters.AsSpan(0, methodParameters.Length - 1).GetArray()); } } } } } }
public async Task ShouldInvokeSynchronousOutVoidMethod(string expected) { var method = GetMethod(nameof(SynchronousOutVoid)); var invoker = new MethodInvoker(Mock.Of <ILogger <MethodInvoker> >()); var arguments = new MethodParameter[] { new MethodParameter { Name = "value", Value = expected }, new MethodParameter { Name = "copy", Out = true } }; var result = await invoker.InvokeMethodAsync(this, method, arguments); Assert.NotNull(result); Assert.True(result.IsVoid); Assert.False(result.IsAsync); Assert.Null(result.Result); Assert.Equal(expected, _value); Assert.Contains("copy", result.OutParameters); Assert.Equal(expected, result.OutParameters["copy"]); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private static ParameterSyntax EmitParameterSyntax(MethodParameter parameter) { var syntax = Parameter(Identifier(parameter.Name)); switch (parameter.Modifier) { case MethodParameterModifier.Ref: syntax = syntax.WithModifiers(TokenList(Token(SyntaxKind.RefKeyword))); break; case MethodParameterModifier.Out: syntax = syntax.WithModifiers(TokenList(Token(SyntaxKind.OutKeyword))); break; } syntax = syntax.WithType(parameter.Type.GetTypeNameSyntax()); return(syntax); }
private void OnPropertiesListChanged(object sender, ListChangedEventArgs e) { if (e.ListChangedType != ListChangedType.ItemAdded) { return; } var property = ((PropertyCollection)sender)[e.NewIndex]; if (!MustEncrypt(property)) { return; } property.DbType = System.Data.DbType.Binary; property.MaxLength = 8000; if (property.Entity.AmbientParameters[PassPhraseToken] != null) { return; } // create one pass phrase ambient parameter for each entity that has at least one crypt property var passPhraseParameter = new MethodParameter { Name = PassPhraseToken, ClrFullTypeName = "string", Nullable = CodeFluent.Model.Code.Nullable.False, Options = MethodParameterOptions.Ambient | MethodParameterOptions.Inherits | MethodParameterOptions.UsedForLoad | MethodParameterOptions.UsedForSearch | MethodParameterOptions.UsedForCount | MethodParameterOptions.UsedForRaw | MethodParameterOptions.UsedForSave, ModelName = "[" + Project.DefaultNamespace + ".PassPhrase.GetPassPhrase()]", AmbientExpression = "(1=1)" }; property.Entity.AmbientParameters.Add(passPhraseParameter); }
protected string GetStringParameter(string name, bool isRequired = false) { MethodParameter p = ServiceBroker.Service.ServiceObjects[0].Methods[0].MethodParameters[name]; if (p == null) { if (isRequired) { throw new ArgumentException(string.Format(Constants.ErrorMessages.RequiredParameterNotFound, name)); } return(string.Empty); } string val = p.Value as string; if (isRequired && string.IsNullOrWhiteSpace(val)) { throw new ArgumentException(string.Format("{0} is required but is empty.", name)); } return(val); }
/// <summary> /// Gets the code for multiple parameters. /// </summary> /// <param name="parameters">The parameters.</param> /// <returns>The code.</returns> public virtual string GetParameters(MethodParameter[] parameters) { if (parameters == null) return string.Empty; var sb = new StringBuilder(); for (var i = 0; i < parameters.Length; i++) { sb.Append(GetParameter(parameters[i])); if (i < parameters.Length - 1) sb.Append(ParameterSpacer); } return sb.ToString(); }
/// <summary> /// Gets the code for creating a parameter. /// </summary> /// <param name="parameter">The parameter.</param> /// <returns>The code.</returns> public virtual string GetParameter(MethodParameter parameter) { return parameter.Type + " " + parameter.Name; }
/// <summary> /// Gets the code for a method header. /// </summary> /// <param name="methodName">Name of the method.</param> /// <param name="visibility">The visibility.</param> /// <param name="parameters">The parameters.</param> /// <param name="returnType">Type of the return.</param> /// <param name="isVirtual">If this method will be virtual.</param> /// <param name="isStatic">If this method will be static.</param> /// <returns>The code.</returns> public virtual string GetMethodHeader(string methodName, MemberVisibilityLevel visibility, MethodParameter[] parameters, string returnType, bool isVirtual, bool isStatic) { var sb = new StringBuilder(256); sb.Append(GetMethodNameAndVisibility(methodName, visibility, returnType, isVirtual, isStatic)); // Parameters sb.Append(OpenParameterString); sb.Append(GetParameters(parameters)); sb.Append(CloseParameterString); return sb.ToString(); }
/// <summary> /// Gets the code for a method header. /// </summary> /// <param name="methodName">Name of the method.</param> /// <param name="visibility">The visibility.</param> /// <param name="parameters">The parameters.</param> /// <param name="returnType">Type of the return.</param> /// <param name="isVirtual">If this method will be virtual.</param> /// <param name="isStatic">If this method will be static.</param> /// <returns>The code.</returns> public string GetMethodHeader(string methodName, MemberVisibilityLevel visibility, MethodParameter[] parameters, Type returnType, bool isVirtual, bool isStatic) { return GetMethodHeader(methodName, visibility, parameters, GetTypeString(returnType), isVirtual, isStatic); }
/// <summary> /// Gets the code for the header of an extension method. /// </summary> /// <param name="methodName">Name of the method.</param> /// <param name="extender">The extender.</param> /// <param name="parameters">The parameters.</param> /// <param name="returnType">Type of the return.</param> /// <returns>The code.</returns> public virtual string GetExtensionMethodHeader(string methodName, MethodParameter extender, MethodParameter[] parameters, Type returnType) { var sb = new StringBuilder(256); sb.Append(GetMethodNameAndVisibility(methodName, MemberVisibilityLevel.Public, returnType, false, true)); sb.Append(OpenParameterString); // First parameter sb.Append("this "); sb.Append(GetParameter(extender)); // Additional parameters if (parameters != null && parameters.Length > 0) { sb.Append(ParameterSpacer); sb.Append(GetParameters(parameters)); } sb.Append(CloseParameterString); return sb.ToString(); }
/// <summary> /// Gets the header for a constructor. /// </summary> /// <param name="className">Name of the class.</param> /// <param name="visibility">The visibility.</param> /// <param name="parameters">The parameters.</param> /// <returns>The code.</returns> public virtual string GetConstructorHeader(string className, MemberVisibilityLevel visibility, MethodParameter[] parameters) { return GetMethodHeader(className, visibility, parameters, string.Empty, false, false); }
private bool IsEnabled(MethodParameter parameter) { if (parameter.IsPagingParameter) return false; return parameter.GetAttributeValue("enabled", NamespaceUri, true); }
private FilterFunctions GetFilterFunctions(MethodParameter parameter) { if (parameter == null) return DefaultFilterFunctions; FilterFunctions defaultValue = GetDefaultFilterFunctions(parameter.Method); return parameter.GetAttributeValue("filterFunctions", NamespaceUri, defaultValue); }
public override List<ServiceObject> DescribeServiceObjects() { string[] ldaps = base.LDAPPaths.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); string[] netbios = base.NetBiosNames.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (ldaps.Length != netbios.Length) { throw new ArgumentException("The LDAP paths and NetBioses count do not match."); } ServiceObject soUser = Helper.CreateServiceObject("AD User", "Active Directory User."); soUser.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ActiveDirectory.UserFQN, SoType.Text, "The FQN username. Domain\\samlaccountname")); soUser.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ActiveDirectory.SubStringSearchInput, SoType.Text, "The string used to search for a specific value.")); soUser.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ActiveDirectory.SamAccountName, SoType.Text, "The SAM Account name")); soUser.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ActiveDirectory.Name, SoType.Text, "The name of the user")); soUser.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ActiveDirectory.Description, SoType.Text, "Description")); soUser.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ActiveDirectory.Email, SoType.Text, "Email Address")); soUser.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ActiveDirectory.Manager, SoType.Text, "The Manager")); soUser.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ActiveDirectory.ObjectSID, SoType.Text, "An objectSID")); soUser.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ActiveDirectory.DisplayName, SoType.Text, "Display Name")); soUser.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ActiveDirectory.CommonName, SoType.Text, "The common name of the object.")); soUser.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ActiveDirectory.GivenName, SoType.Text, "Given Name")); soUser.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ActiveDirectory.Initials, SoType.Text, "Initials")); soUser.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ActiveDirectory.Surname, SoType.Text, "Surname")); soUser.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ActiveDirectory.MaxSearchResultSize, SoType.Number, "Override the default max result size per LDAP directory.")); soUser.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ActiveDirectory.OrganisationalUnit, SoType.Text, "OrganisationalUnit")); foreach (string prop in AdditionalADProps) { soUser.Properties.Add(Helper.CreateProperty(prop, SoType.Text, prop)); } Method mGetUsers = Helper.CreateMethod(Constants.Methods.ActiveDirectory.GetUsers, "Get all users, filtered by exact matching of the input properties.", MethodType.List); mGetUsers.InputProperties.Add(Constants.SOProperties.ActiveDirectory.UserFQN); mGetUsers.InputProperties.Add(Constants.SOProperties.ActiveDirectory.DisplayName); mGetUsers.InputProperties.Add(Constants.SOProperties.ActiveDirectory.Email); mGetUsers.InputProperties.Add(Constants.SOProperties.ActiveDirectory.MaxSearchResultSize); mGetUsers.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.UserFQN); mGetUsers.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.SamAccountName); mGetUsers.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.DisplayName); mGetUsers.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.Email); foreach (string prop in AdditionalADProps) { mGetUsers.ReturnProperties.Add(prop); } soUser.Methods.Add(mGetUsers); Method mGetUserDetails = Helper.CreateMethod(Constants.Methods.ActiveDirectory.GetUserDetails, "Get all details for the users.", MethodType.Read); mGetUserDetails.InputProperties.Add(Constants.SOProperties.ActiveDirectory.UserFQN); mGetUserDetails.Validation.RequiredProperties.Add(Constants.SOProperties.ActiveDirectory.UserFQN); mGetUserDetails.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.SamAccountName); mGetUserDetails.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.DisplayName); mGetUserDetails.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.CommonName); mGetUserDetails.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.GivenName); mGetUserDetails.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.Initials); mGetUserDetails.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.Surname); mGetUserDetails.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.Email); mGetUserDetails.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.OrganisationalUnit); foreach (string prop in AdditionalADProps) { mGetUserDetails.ReturnProperties.Add(prop); } soUser.Methods.Add(mGetUserDetails); Method mSearchUser = Helper.CreateMethod(Constants.Methods.ActiveDirectory.SearchUsers, "Performs a StartWith query on DisplayName, SamlAccountName and E-mail.", MethodType.List); mSearchUser.InputProperties.Add(Constants.SOProperties.ActiveDirectory.SubStringSearchInput); mSearchUser.InputProperties.Add(Constants.SOProperties.ActiveDirectory.MaxSearchResultSize); mSearchUser.Validation.RequiredProperties.Add(Constants.SOProperties.ActiveDirectory.SubStringSearchInput); mSearchUser.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.UserFQN); mSearchUser.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.SamAccountName); mSearchUser.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.DisplayName); mSearchUser.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.Email); soUser.Methods.Add(mSearchUser); Method mUMGetUsers = Helper.CreateMethod(Constants.Methods.ActiveDirectory.UMGetUsers, "Performs a search using FILTERs provided to the SMO.", MethodType.List); mUMGetUsers.InputProperties.Add(Constants.SOProperties.ActiveDirectory.Name); mUMGetUsers.InputProperties.Add(Constants.SOProperties.ActiveDirectory.Description); mUMGetUsers.InputProperties.Add(Constants.SOProperties.ActiveDirectory.Email); mUMGetUsers.InputProperties.Add(Constants.SOProperties.ActiveDirectory.Manager); mUMGetUsers.InputProperties.Add(Constants.SOProperties.ActiveDirectory.DisplayName); mUMGetUsers.InputProperties.Add(Constants.SOProperties.ActiveDirectory.MaxSearchResultSize); mUMGetUsers.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.UserFQN); mUMGetUsers.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.Name); mUMGetUsers.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.Description); mUMGetUsers.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.DisplayName); mUMGetUsers.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.Email); mUMGetUsers.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.Manager); mUMGetUsers.ReturnProperties.Add(Constants.SOProperties.ActiveDirectory.ObjectSID); MethodParameter methParm = new MethodParameter(); methParm.IsRequired = true; methParm.MetaData = new SourceCode.SmartObjects.Services.ServiceSDK.Objects.MetaData(); methParm.MetaData.Description = Constants.SOProperties.ActiveDirectory.Label; methParm.MetaData.DisplayName = Constants.SOProperties.ActiveDirectory.Label; methParm.Name = Constants.SOProperties.ActiveDirectory.Label; methParm.SoType = SoType.Text; methParm.Type = MapHelper.GetTypeBySoType(methParm.SoType); mUMGetUsers.MethodParameters.Add(methParm); soUser.Methods.Add(mUMGetUsers); return new List<ServiceObject>() { soUser }; }
private void OnPropertiesListChanged(object sender, ListChangedEventArgs e) { if (e.ListChangedType != ListChangedType.ItemAdded) return; var property = ((PropertyCollection)sender)[e.NewIndex]; if (!MustEncrypt(property)) return; property.DbType = System.Data.DbType.Binary; property.MaxLength = 8000; if (property.Entity.AmbientParameters[PassPhraseParameterName] != null) return; // create one pass phrase ambient parameter for each entity that has at least one crypt property var passPhraseParameter = new MethodParameter { Name = PassPhraseParameterName, ClrFullTypeName = "string", Nullable = CodeFluent.Model.Code.Nullable.False, Options = MethodParameterOptions.Ambient | MethodParameterOptions.Inherits | MethodParameterOptions.UsedForLoad | MethodParameterOptions.UsedForSearch | MethodParameterOptions.UsedForCount | MethodParameterOptions.UsedForRaw | MethodParameterOptions.UsedForSave, ModelName = "[" + Project.DefaultNamespace + ".PassPhrase.GetPassPhrase()]", AmbientExpression = "(1=1)" }; property.Entity.AmbientParameters.Add(passPhraseParameter); }
private string GetMethodParameterName(MethodParameter parameter) { string name = parameter.GetAttributeValue("parameterNameFormat", NamespaceUri, (string)null); if (!string.IsNullOrEmpty(name)) return name; string format = GetMethodParameterNameFormat(parameter.Method); return string.Format(format, parameter.Name); }
public VariableAssignmentAction(Func<MethodBuilderBundle> bundle, int localIndex, MethodParameter parameter) : this(bundle, localIndex) { this.parameter = parameter; }
public static MethodParameter CreateParameter(string name, SoType soType, bool isRequired, string description) { MethodParameter methodParam = new MethodParameter { Name = name, IsRequired = isRequired, MetaData = new MetaData { Description = description, DisplayName = AddSpaceBeforeCaptialLetter(name) }, SoType = soType, Type = Convert.ToString(soType) }; return methodParam; }
private void UpdateMethods() { // Add arguments Search method // SEARCH(FirstName, LastName) // => SEARCH(FirstName, FirstNameFilterFunction, LastName, LastNameFilterFunction) foreach (var entity in Project.Entities) { foreach (var method in entity.Methods) { if (!IsEnabled(method)) continue; int newParameterCount = 0; foreach (var parameter in method.Parameters.Clone()) { if (!IsEnabled(parameter)) continue; newParameterCount += 1; MethodParameter newParameter = new MethodParameter(); newParameter.Name = GetMethodParameterName(parameter); newParameter.ClrFullTypeName = FilterFunctionsEnumeration.ClrFullTypeName; newParameter.DbType = FilterFunctionsEnumeration.EnumDbType; newParameter.MustUsePersistenceDefaultValue = false; newParameter.Nullable = Nullable.False; newParameter.ModelNullable = Nullable.False; method.Parameters.Insert(parameter.Index + newParameterCount, newParameter); newParameter.Data[NamespaceUri + ":parameter"] = parameter; // Save the original parameter to retrieve it when updating the procedure } } } }